<style>
    .layui-form-item .layui-input-company {
        width: auto;
        padding-right: 10px;
        line-height: 38px;
    }
</style>
<div class="layuimini-container layuimini-page-anim">
  <div class="layuimini-main">

    <div class="layui-form layuimini-form">
      <div class="layui-form-item">
        <label class="layui-form-label required">管理账号</label>
        <div class="layui-input-block">
          <input type="text" id="mobile" name="mobile" class="layui-input" lay-verify="required" lay-reqtext="手机号不能为空"
                 value="" placeholder="请输入手机号" readonly/>
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label required">用户昵称</label>
        <div class="layui-input-block">
          <input class="layui-input" name="userName" lay-verify="required" lay-reqtext="昵称不能为空"
                 placeholder="请输入用户昵称" value="">
        </div>
      </div>

      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
      </div>
    </div>
  </div>
</div>
</html>
<script>
    layui.use(['form', 'miniPage'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniPage = layui.miniPage,
            $ = layui.jquery;

        $.ajax({
            url: "/user/getMobile",
            type: "GET",
            success: function (data) {
                if (data.code == 200) {
                    $('#mobile').val(data.object);
                } else {
                    layer.msg(data.message);
                }
            }
        });

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert("手机号：" + data.field.mobile + "，昵称：" + data.field.userName, {
                title: '最终的提交信息'
            }, function () {
                $.ajax({
                    url: "/user/updateUserMsg",
                    type: "POST",
                    dataType: 'json',
                    data: JSON.stringify(data.field),
                    contentType: 'application/json;charset=utf-8',
                    success: function (data) {
                        if (data.code == 200) {
                            layer.msg("昵称修改成功！")
                            setTimeout(function (){
                                location.reload()
                            }, 2000)
                        } else {
                            layer.msg(data.message);
                            layer.close(index);
                        }
                    }
                });
            });
            return false;
        });
    });
</script>